package com.doit.day03

import scala.collection.mutable.ArrayBuffer

object _01_不可变数组 {
  def main(args: Array[String]): Unit = {
    val arr: Array[Int] = Array(1, 2, 3, 4, 5, 6)
    val res: Array[Int] = arr.drop(2) //从左到右删除n个元素
    println(res.mkString(","))//3,4,5,6

    val res1: Array[Int] = arr.dropRight(2)
    println(res1.mkString(","))//1,2,3,4

    val res2: Array[Int] = arr.dropWhile((a: Int) => {
      a % 2 == 1
    })

    println(res2.mkString(",")) // 1,2,3,4,5,6  2,3,4,5,6


    val buffer: ArrayBuffer[Int] = new ArrayBuffer[Int]()
    buffer.append(1)
    println(buffer)
    buffer.append(2)
    println(buffer)
    buffer.append(3)
    println(buffer)
    buffer.append(4)
    println(buffer)//1 2 3 4
    buffer.insert(2,100)
    println(buffer)//1 2 100 3 4

    buffer.insertAll(2,arr)//1 2 1 2 3 4 5 6 100 3 4
    println(buffer)

    val i: Int = buffer(1)

    val list: List[Array[Int]] = List(Array(1, 2, 3, 4), Array(5, 6, 7))
    println(list.flatten)

    val list1: List[List[List[Int]]] = List(List(List(1, 2), List(3, 4)), List(List(5, 6), List(7, 8)))
    println(list1.flatten.flatten)

  }

}
